<?php

namespace backend\controllers;

use bc\controller\BackendController;
use bc\model\product\QrcodeModel;
use bc\service\SpokesmanService;
use bc\model\order\report\ShareModel;
use api\controllers\SzController;
use bc\service\gene\FpService;
use bc\util\ImageMergeQrcode;

class Test1Controller extends \bc\controller\BackendController
{
    public function actionTest(){
        
        $user = array();
        $user['user_id'] = $this->get('user_id');
        
        $qrcodeModel = new QrcodeModel();
        $qrcode = $qrcodeModel->getRow(['user_id' => $user['user_id'], 'product_id' => 2, 'is_delete' => 0 ]);
						
						
        if(!$qrcode)
        {      
                echo 111;
                //创建用户专属二维码
                $spokesmanService = new SpokesmanService();
                $spokesmanService->createProductQrcode(2, $user);
        }
    }
    
    public function actionTest1(){
        
        echo 222;
        $spokesmanService = new SpokesmanService();
        $orderItem['product_id'] = 2;
        $orderItem['user_id'] = $this->get('user_id');
        $recommendProduct['parent_user_id'] = 0;
        $spokesmanService->createLevel($orderItem['product_id'], $orderItem['user_id'], $recommendProduct['parent_user_id']);
    
        
    }
    
    public function  actionTest2(){
        echo 33;
        
        $user_id = $this->get('user_id');
        $model = new \bc\model\BindModel();
        $bind = $model->getRow(['user_id'=>$user_id]);
        
        $service = new FpService();
        $backgroundImage = $service->getReportTemplate($bind['bind_no']);
        
        $qrcodeModel = new QrcodeModel();
        $qrcode = $qrcodeModel->getRow(['product_id' => 2, 'user_id' => $user_id, 'is_delete' => 0]);

        $newImage = 'qrcode/product/' . time() . '.jpg';
        //合并图片
        $imageMergeQrcode = new ImageMergeQrcode(STATIC_IMAGE . $backgroundImage, STATIC_IMAGE . $qrcode['qrcode_image']);
        $imageMergeQrcode->setX(282);
        $imageMergeQrcode->setY(1043);
        $imageMergeQrcode->create(UPLOAD_PATH . $newImage);

        $shareModel = new ShareModel();

        $shareData['share_image'] = $newImage;
        $shareData['bind_no'] = $bind['bind_no'];
        $shareData['is_del'] = 0;
        $shareData['create_time'] = $shareData['update_time'] = date('Y-m-d H:i:s');
        $shareModel->add($shareData);
        
    }
    
}


